package com.qinggeng.project.tool.pay.service.impl;

import com.qinggeng.common.enums.CommonEnum;
import com.qinggeng.project.system.domain.Orders;
import com.qinggeng.project.system.service.IOrdersService;
import com.qinggeng.project.tool.pay.domain.vo.TradeVo;
import com.qinggeng.project.tool.pay.service.FreePayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author 吴鹏飞
 * @date 2020/8/20
 */

@Service
@Slf4j
public class FreePayServiceImpl implements FreePayService {
    @Autowired
    private IOrdersService ordersService;
    @Override
    public String toPayForFree(TradeVo tradeVo) throws Exception {
        try {
            Orders orders = ordersService.selectOrdersByOrdersNo(tradeVo.getOutTradeNo());
            if (orders == null){
                return "订单不存在";
            }
            orders.setPayStatus(CommonEnum.STATUS_20.getValue());
            orders.setPayTime(new Date());
            ordersService.insertOrders(orders);
        } catch (Exception e) {
            e.getStackTrace();
        }
        return "支付成功";
    }
}
